package jtg;

import soot.Unit;
import soot.toolkits.graph.UnitGraph;

import java.util.ArrayList;
import java.util.List;

public class DirectedGraph {
    public int n;//结点数
    public int m;//边数
    public boolean[][] edge;
    public List<Unit> vertex;
    public List<Unit> head;
    public List<Unit> tail;

    public DirectedGraph(int n){
        this.n=n;
        this.m=0;
        this.edge=new boolean[n+1][n+1];
        this.vertex=new ArrayList<>();
        this.head=new ArrayList<>();
        this.tail=new ArrayList<>();
    }

    public void addVertex(Unit u){
        vertex.add(u);
    }

    public void addEdge(Unit u,Unit v){
        edge[vertex.indexOf(u)][vertex.indexOf(v)]=true;
        m+=1;
    }

    public void generateGraph(UnitGraph ug){
        for(Unit u:ug){
            addVertex(u);
        }
        for(Unit u:ug){
            for(Unit v:ug.getSuccsOf(u)){
                addEdge(u,v);
            }
        }
        head=ug.getHeads();
        tail=ug.getTails();
    }
}
